package com.zyf.pattern.proxy.custom;

import com.zyf.pattern.proxy.jdk.Person;

import java.lang.reflect.Method;

/**
 * create by yifeng
 */
public class CustomMeipo implements CInvocationHandler{

    private Person target;

    public Object getInstance(Person target) {
        this.target = target;

        Class<?> clazz = target.getClass();

        return CProxy.newProxyInstance(new CClassLoader(), clazz.getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("我是媒婆，我要给你找对象，现在已经" +
                "拿到你的需求");
        System.out.println("开始物色");
        method.invoke(this.target, args);
        System.out.println("如果条件符合，则开始办事");
        return null;
    }
}
